package proto;

import java.util.Date;

/**
 *
 * Levels of the game, containing tiles.
 * @author Bitjaeger
 *
 */
public class Level {
    private Tile[][] tiles;
    private Tile emptyTile;
    private Point[] startingPositions;  // for the stickmen
    private boolean isComplete;
	private long start;

    /**
    * C'tor copies the tile array
    * @param tiles
    */
    public Level(Tile[][] tiles, Tile emptyTile) {
        this.tiles = tiles;
        this.emptyTile = emptyTile;
        this.isComplete = false;
		start = System.currentTimeMillis();
    }

    /**
     * Used when creating the stickman.
     * @return the starting position for the stickman
     */
    public Point GetStartingPosition(int i) {
        return startingPositions[i];
    }
    
    /**
     * Set the starting position for the two stickmen.
     * Loader calls this.
     * @param positions Point positions for the stickmen.
     */
    public void SetStartingPositions(Point[] positions) {
        startingPositions = positions;
    }

    public Tile GetEmptyTile() {
        return emptyTile;
    }
    
    /**
    *
    * @return Number of rows
    */
    public int GetRowCount() {
        return tiles[0].length;
    }
    /**
    *
    * @return Number of columns
    */
    public int GetColumnCount() {
        return tiles.length;
    }

    public Tile GetUpperLeftTile() {
        for (int y = 0; y < tiles[0].length; y++) {
            for (int x = 0; x < tiles.length; x++) {
                if(tiles[x][y].GetNeighbor(Direction.UP)==null && 
                        tiles[x][y].GetNeighbor(Direction.LEFT)==null){
                    return tiles[x][y];
                }
            }
        }
        return null;
    }
    
    
    public void SetComplete() {
        isComplete = true;
    }
    
    public boolean IsComplete() {
        return isComplete;
    }
	
	public String getTime()
	{
		long time = System.currentTimeMillis()-start;
		long hours = time/1000/3600;
		time -= hours*1000*3600;
		long minutes = time/1000/60;
		time -= minutes*1000*60;
		long seconds = time/1000;
		String s;
		if(hours<10)
			s = "0"+hours;
		else
			s = hours+"";
		if(minutes<10)
			s += ":0"+minutes;
		else
			s += ":"+minutes+"";
		if(seconds<10)
			s += ":0"+seconds;
		else
			s += ":"+seconds+"";
		return s;
	}
}
